package org.git.movie.controller;

import com.alibaba.fastjson.JSONObject;
import org.git.movie.annotations.Verify;
import org.git.movie.entity.LogWebsiteVisit;
import org.git.movie.service.ILogWebsiteVisitService;
import org.git.movie.util.BaseController;
import org.git.movie.util.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
@RestController
public class LogWebsiteVisitController extends BaseController {

    @Autowired
    private ILogWebsiteVisitService logWebsiteVisitService;

    @PostMapping(value = "/log/doinsert.do" ,consumes="application/json;charset=UTF-8")
    public BaseResponse<JSONObject> doinsert(
            HttpServletResponse response,
            @RequestBody @Valid LogWebsiteVisit record, BindingResult result

    ){

        if(result.hasErrors()){
            String msg = null;
            for (ObjectError error : result.getAllErrors()) {

                msg = error.getDefaultMessage();
                break;
            }
            responseValidErrorMsg(  response,  "400",msg);
            return null;
        }
       int rows =  logWebsiteVisitService.insert(record);
        JSONObject rep = new JSONObject();
        rep.put("insertrow",rows);
        return   ok(rep);

    }
}
